ARG TAG=3.9.5-alpine

FROM python:${TAG}

ENV PYTHONUNBUFFERED=1

ENV APP_USER=mini

ARG UID=998
# N.B.: The group id 999 is occupied by the `ping` utility.
ARG GID=998

RUN set -eux \
    && addgroup --system --gid ${GID} "${APP_USER}" \
    && adduser --system --no-create-home \
        --uid ${UID} \
        --gecos '' \
        --ingroup "${APP_USER}" \
        --disabled-password \
        "${APP_USER}"

RUN apk add --no-cache openssl ca-certificates

WORKDIR /opt/requirements

COPY requirements.txt  ./

RUN set -eux \
    && sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories \
    && apk add --virtual .build-deps build-base yaml-dev \
    && pip install -i https://pypi.mirrors.ustc.edu.cn/simple/ --requirement requirements.txt \
    && rm -rf /root/.cache \
    && apk del .build-deps \
    && rm -rf /var/cache/apk/*


COPY app.py config.py  ./
EXPOSE 8000

CMD gunicorn -c config.py app:app